﻿@page "/"
@using Microsoft.AspNetCore.Components.Web
@namespace BlazorSample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="~/" />
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="BlazorSample.styles.css" rel="stylesheet" />
    <link rel="icon" type="image/png" href="favicon.png"/>
    <link href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css" rel="stylesheet" />
    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
    <component type="typeof(App)" render-mode="ServerPrerendered" />

    <div id="blazor-error-ui" data-nosnippet>
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>

    <script src="_framework/blazor.server.js"></script>

    <script>
        window.convertArray = (win1251Array) => {
            var win1251decoder = new TextDecoder('windows-1251');
            var bytes = new Uint8Array(win1251Array);
            var decodedArray = win1251decoder.decode(bytes);
            return decodedArray;
        };
    </script>
    <script>
        window.returnObjectReference = () => {
            return {
                unmarshalledFunctionReturnBoolean: function (fields) {
                    const name = Blazor.platform.readStringField(fields, 0);
                    const year = Blazor.platform.readInt32Field(fields, 8);

                    return name === "Brigadier Alistair Gordon Lethbridge-Stewart" &&
                        year === 1968;
                },
                unmarshalledFunctionReturnString: function (fields) {
                    const name = Blazor.platform.readStringField(fields, 0);
                    const year = Blazor.platform.readInt32Field(fields, 8);

                    return BINDING.js_string_to_mono_string(`Hello, ${name} (${year})!`);
                }
            };
        }
    </script>
    <script>
        window.displayTickerAlert1 = (symbol, price) => {
            alert(`${symbol}: $${price}!`);
        };
    </script>
    <script>
        window.displayTickerAlert2 = (symbol, price) => {
            if (price < 20) {
                alert(`${symbol}: $${price}!`);
                return "Alert!";
            } else {
                return "No Alert";
            }
        };
    </script>
    <script>
        function setElementClass(element, className) {
            var myElement = element;
            myElement.classList.add(className);
        }
    </script>
    <script>
        window.returnArrayAsync = () => {
            DotNet.invokeMethodAsync('BlazorSample', 'ReturnArrayAsync')
                .then(data => {
                    console.log(data);
                });
        };
    </script>
    <script>
        window.sayHello1 = (dotNetHelper) => {
            return dotNetHelper.invokeMethodAsync('GetHelloMessage');
        };
    </script>
    <script>
        window.sayHello2 = (dotNetHelper, name) => {
            return dotNetHelper.invokeMethodAsync('GetHelloMessage', name);
        };
    </script>
    <script>
        window.updateMessageCaller = (dotnetHelper) => {
            dotnetHelper.invokeMethodAsync('UpdateMessageCaller');
            dotnetHelper.dispose();
        }
    </script>
    <script>
        window.downloadFileFromStream = async (fileName, contentStreamReference) => {
            const arrayBuffer = await contentStreamReference.arrayBuffer();
            const blob = new Blob([arrayBuffer]);
            const url = URL.createObjectURL(blob);
            const anchorElement = document.createElement('a');
            anchorElement.href = url;
            anchorElement.download = fileName ?? '';
            anchorElement.click();
            anchorElement.remove();
            URL.revokeObjectURL(url);
        }
        window.triggerFileDownload = (fileName, url) => {
            const anchorElement = document.createElement('a');
            anchorElement.href = url;
            anchorElement.download = fileName ?? '';
            anchorElement.click();
            anchorElement.remove();
        }
    </script>
    <script>
        window.setSource = async (elementId, stream, contentType, title) => {
          const arrayBuffer = await stream.arrayBuffer();
          let blobOptions = {};
          if (contentType) {
            blobOptions['type'] = contentType;
          }
          const blob = new Blob([arrayBuffer], blobOptions);
          const url = URL.createObjectURL(blob);
          const element = document.getElementById(elementId);
          element.title = title;
          element.onload = () => {
            URL.revokeObjectURL(url);
          }
          element.src = url;
        }
    </script>
    <script>
        window.assignDotNetHelper = (element, dotNetHelper) => {
            element.dotNetHelper = dotNetHelper;
        }

        window.interopCall = async (element) => {
            await element.dotNetHelper.invokeMethodAsync('UpdateMessage');
        }
    </script>
    <script>
      window.sendByteArray = () => {
        const data = new Uint8Array([0x45,0x76,0x65,0x72,0x79,0x74,0x68,0x69,
          0x6e,0x67,0x27,0x73,0x20,0x73,0x68,0x69,0x6e,0x79,0x2c,
          0x20,0x43,0x61,0x70,0x74,0x61,0x69,0x6e,0x2e,0x20,0x4e,
          0x6f,0x74,0x20,0x74,0x6f,0x20,0x66,0x72,0x65,0x74,0x2e]);
        DotNet.invokeMethodAsync('BlazorSample', 'ReceiveByteArray', data)
          .then(str => {
            alert(str);
          });
      };
    </script>
    <script>
        window.scrollElementIntoView = (element) => {
          element.scrollIntoView();
          return element.getBoundingClientRect().top;
        }
    </script>
</body>
</html>
